<?php

class room_IndexController extends Zend_Controller_Action
{
public function init()
    {
        /* Initialize action controller here */
    	defined('BASE_URL')	|| define('BASE_URL', Zend_Controller_Front::getInstance()->getBaseUrl());
    }

    public function indexAction()
    {
    	
    	
	}
	public function listAction()
	{
		$db = new room_Model_DbTable_Dbroom();
		//print_r($data);exit();
		$this->_helper->layout()->disableLayout();
		if($this->getRequest()->isPost()){	
			$is = $this->getRequest()->getPost();
			//print_r($is);exit();
			if($this->getRequest()->getParam("edit")){
				$id = $this->getRequest()->getParam("chk_modify");
				//print_r($is);exit();
				if(!empty($id)){
					$this->_redirect("/room/index/edit/id/".$id);
					$frm = new room_Form_Frmroom();
					$row = $db->getroom($id);
					$dbdpt = $frm->fromroom($row);
					$this->view->fromroom= $dbdpt;
				}
				$this->_redirect("/room/index/list");
			}
			if($this->getRequest()->getParam("delete")){
				$id = $this->getRequest()->getParam("chk_modify");
				//print_r($id); exit;
				if(!empty($id)){
					$db->deleteroom($id);
					$this->_redirect("room/index/list");
					echo "<script type='text/javascript'> alert('Delete room Successfull'); </script>";
				}
				$this->_redirect("faculty/index/index");
			}
			if($this->getRequest()->getPost("status")){
				$id = $this->getRequest()->getParam("status");
				//print_r($id);exit();
				if(!empty($id)){
					$dbdpt = $db->updateUnStatus ($id);
					//echo "<script type='text/javascript'> alert('Update Status room Successfull'); </script>";
				}
				//$this->_redirect("faculty/fac/index");
			}
			if($this->getRequest()->getPost("unstatus")){
				$id = $this->getRequest()->getParam("unstatus");
				//print_r($id);exit();
				$dbdpt = $db->updateStatus($id);
				//echo "<script type='text/javascript'> alert('Update Status room Successfull'); </script>";
			}
		}  
		$data = $db->selectroom();
		$this->view->fromroom = $data;
	}
	public function addAction(){
		//$this->_helper->layout()->disableLayout();
		if($this->getRequest()->isPost()){
			$data = $this->getRequest()->getPost();
			$db = new room_Model_DbTable_Dbroom();
			if($this->getRequest()->getParam("save_colse")){
				if($this->getRequest()->getParam("room_name") !=""){
					$db->insertroom($data);
					$this->_redirect("/room/");
				}
				else {
					echo "<script type='text/javascript'> alert('Please Try Again'); </script>";
				}
			}
			elseif($this->getRequest()->getParam("save_new")){
				if($this->getRequest()->getParam("room_name") !=""){
					$db->insertroom($data);
					echo "<script type='text/javascript'> alert('Insert room Successfull'); </script>";
					$this->_redirect("/room/index/add");
				}
				else {
					echo "<script type='text/javascript'> alert('Please Try Again'); </script>";
				}
			}
			elseif ($this->getRequest()->getParam("cancel")) {
				$this->_redirect("/room/index/list");
			}
		}
		$frmrooms = new room_Form_Frmroom();
		$frmadd = $frmrooms->fromroom();
		$this->view->fromroom= $frmadd;
		/////////
		$floor = $frmrooms->formfloor();
		$this->view->formfloors = $floor;
		
	}
	public function  addfloorA(){
		
	}
	public function editAction()
	{
		//$this->_helper->layout()->disableLayout();		
		$db = new room_Model_DbTable_Dbroom();
		if($this->getRequest()->isPost()){
			$data = $this->getRequest()->getPost();
			if($this->getRequest()->getParam("save_colse")){
				$row = $db->updatroom($data);
				//print_r($row);exit();
				$this->_redirect("/room/index/list");
			}
			elseif($this->getRequest()->getParam("save_new")){
				$row = $db->updatroom($data);
				$this->_redirect("/room/index/add");
			}
			elseif ($this->getRequest()->getParam("save")){
				$row = $db->updatroom($data);
				$id = $this->getRequest()->getParam("id");
				$rows = $db->getroom($id);
				$frmrooms = new room_Form_Frmroom();
				$frmedit = $frmrooms->fromroom($rows);
				$this->view->fromroom= $frmedit;
				echo "<script type='text/javascript'> alert('Update Status room Successfull'); </script>";
			}
			elseif ($this->getRequest()->getParam("cancel")) {
				//print_r($data);exit();
				$this->_redirect("/room/index/list");
			}
		}				
		$id = $this->getRequest()->getParam("id");
		$rows = $db->getroom($id);
		//print_r($rows);exit();
		$frmrooms = new room_Form_Frmroom();
		$frmedit = $frmrooms->fromroom($rows);
		$this->view->fromroom= $frmedit;
		
	}
	public function deleteAction(){
		$db = new room_Model_DbTable_Dbroom();
		$id = $this->getRequest()->getParam("id");
		$db->deleteroom($id);
		$this->_redirect("/room/index/list");
	}
}